package com.jsp.servlet; /**
 * @author wzm
 * @create 2023-03-13 10:05
 */

import com.jsp.entity.Employee;
import com.jsp.service.EmployeeService;
import com.jsp.service.impl.EmployeeServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/selectById")
public class SelectByIdServlet extends HttpServlet {
    private EmployeeService employeeService = new EmployeeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String id = request.getParameter("id");
        int i = Integer.parseInt(id);

        Employee empById = employeeService.getEmpById(new Employee(i));

        if(empById != null){
            //成功
            //存储数据
            request.setAttribute("emp",empById);

            request.getRequestDispatcher("/update.jsp").forward(request,response);

        }else{
            //失败
        }
    }
}
